package gui.ScheduleTab;
import java.util.List;
import org.eclipse.nebula.widgets.calendarcombo.CalendarCombo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import common.Tables.Table;
import gui.Interpreter;
/**
 * this class open in separate thread 
 * 			the get psychologists to schedule command to interpreter  
 * @author Orit
 *
 */
public class GetPsycs implements Runnable{
	Interpreter interpreter;		//interpreter each command to send to server
	public boolean done = false;	//notice if the thread done (to keep drawing the GUI)
	private Display display;		//DISPLAY GUI
	private Shell shell;			//shell GUI
	List<Table> ans;				////the answer for get schedule
	
	/**
	 * C'tor
	 * @param interpreter - to send the command
	 * @param display	- of the GUI	
	 * @param shell		- Of the GUI
	 */
	public GetPsycs(Interpreter interpreter ,Display display,Shell shell,CalendarCombo dateTreeText) {
		this.interpreter = interpreter;
		this.display = display;
		this.shell = shell;
	}
	
	/**
	 * run the save schedule command in separate thread and continue drawing
	 */
	public void run(){
		done = false;
		 Thread thread = new Thread(new Runnable() { //open import from file in separate thread
			@Override
			public void run() {
				refreshGui();
				done = true;
				display.wake();
			}

			
		 });
		 thread.start();
        while (!done && !shell.isDisposed()) {   //Continue to draw the main GUI. (no black screen)
          if (!display.readAndDispatch())
            display.sleep();
        }
		
	}
	
	/**
	 * refresh the Gui - get updated data
	 * @return table of psychologists
	 */
	private void refreshGui() {
		this.ans = interpreter.getAllPsychsWithSets();
	}
	
	/**
	 * get Table in Gui
	 * @return table of psychologists
	 */
	public List<Table> getAns() {
		return ans;
	}
	
	/**
	 * is thread was done
	 * @return true if the thread finish false otherwise
	 */
	public boolean isDone() {
		return done;
	}
}
